package com.itheima.app.controller.umsController;

import com.itheima.app.manager.umsManager.UmsResourceCategoryManager;
import com.itheima.commons.R;
import com.itheima.domain.db.ums.UmsResourceCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UmsResourceCategoryController {

    //TODO:江云天 -资源列表

    @Autowired
    private UmsResourceCategoryManager umsResourceCategoryManager;

    /**
     * 增加后台资源
     * @param umsResourceCategory
     * @return
     */
    @PostMapping("/resourceCategory/create")
    public R addResourceCategory(@RequestBody UmsResourceCategory umsResourceCategory) {
        return umsResourceCategoryManager.addResourceCategory(umsResourceCategory);
    }

    /**
     * 根据id删除资源分类
     * @param id
     * @return
     */
    @PostMapping("/resourceCategory/delete/{id}")
    public R deleteResourceCategory(@PathVariable Integer id) {
        return umsResourceCategoryManager.deleteResourceCategory(id);
    }


    /**
     * 修改资源分类
     * @param id
     * @return
     */
    @PostMapping("/resourceCategory/update/{id}")
    public R updateResourceCategory(@PathVariable Integer id, @RequestBody UmsResourceCategory umsResourceCategory) {
        return umsResourceCategoryManager.updateResourceCategory(id, umsResourceCategory);
    }


    /**
     * 查询所有资源分类
     * @return
     */
    @GetMapping("/resourceCategory/listAll")
    public R selectResourceCategoryList() {
        List<UmsResourceCategory> umsResourceCategories = umsResourceCategoryManager.selectResourceCategoryList();
        return R.ok(umsResourceCategories);
    }
}
